﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SyndicateDAO.Classes;
using SyndicateDAO.DatabaseObject;

namespace SyndicateDAO.DAO
{
    public class SyndicatesDAO : DataBaseHelper<syndicate>
    {
        private static UserDAO UserDAO = new UserDAO();

        public syndicate SelectSingleByUserId(int uId)
        {
            return UserDAO.SelectSingle(uId).syndicate;
        }

        public syndicate SelectCurrentSyndicate(int? currentId)
        {
            if (currentId.HasValue)
                return this.SelectAll().SingleOrDefault(s => s.id == currentId);
            else
            {
                return this.SelectAll().SingleOrDefault(s => s.isCurrent);
            }
            
        }

        public syndicate SelectCurrentSyndicate()
        {
            return SelectCurrentSyndicate(default(int));
        }

        public bool InserSyndicate(syndicate s)
        {
            return this.Insert(s);
        }
        public bool UpdateSyndicate()
        {
            return this.Update();
        }
        public bool DeleteSyndicate(syndicate s)
        {
            return this.Delete(s);
        }
    }
}
